<?php
			function check_required_fields($required_array,$CHK) {
				$field_errors = array();
				foreach($required_array as $fieldname) {
					if (!isset($CHK[$fieldname]) || (empty($CHK[$fieldname]) && $CHK[$fieldname] != 0)) { 
						$field_errors[] = $fieldname; 
					}
				}
				return $field_errors;
			}

			function mysql_prep( $value ) {
				$magic_quotes_active = get_magic_quotes_gpc();
				$new_enough_php = function_exists( "mysql_real_escape_string" ); // i.e. PHP >= v4.3.0
				if( $new_enough_php ) { // PHP v4.3.0 or higher
					// undo any magic quote effects so mysql_real_escape_string can do the work
					if( $magic_quotes_active ) { $value = stripslashes( $value ); }
					$value = mysql_real_escape_string( $value );
				} else { // before PHP v4.3.0
					// if magic quotes aren't already on then add slashes manually
					if( !$magic_quotes_active ) { $value = addslashes( $value ); }
					// if magic quotes are active, then the slashes already exist
				}
				return $value;
			}

			function check_max_field_lengths($field_length_array,$CHK) {
				$field_errors = array();
				foreach($field_length_array as $fieldname => $maxlength ) {
					if (strlen(trim(mysql_prep($CHK[$fieldname]))) > $maxlength) { $field_errors[] = $fieldname; }
				}
				
				return $field_errors;
			}
			function check_min_field_lengths($field_length_array,$CHK) {
				$field_errors = array();
				foreach($field_length_array as $fieldname => $minlength ) {
					if (strlen(trim(mysql_prep($CHK[$fieldname]))) < $minlength) { $field_errors[] = $fieldname; }
				}
				return $field_errors;
			}
			function check_numberic($field_length_array,$CHK) {
				$field_errors = array();
				foreach ($field_length_array as $fieldname) {
					if (!is_numeric(trim(mysql_prep($CHK[$fieldname])))) { $field_errors[] = $fieldname; }
				}
				return $field_errors;
			}

			// function display_errors($error_array) {
			// 	echo "<p class=\"errors\">";
			// 	echo "Please review the following fields:<br />";
			// 	foreach($error_array as $error) {
			// 		echo " - " . $error . "<br />";
			// 	}
			// 	echo "</p>";
			// }

?>